<template>
  <!-- 外观检查 -->
  <basic-container shadow="hover">
    <crud-title :title="title" />
    <avue-form v-loading="loading" ref="form" :option="option" v-model="form">
      <template slot="attachVOS">
        <easy-upload
          style="display: inline"
          :drag="false"
          v-model="form.attachVOS"
          :disabled="['view'].includes(type)"
          :view-with-count="['view'].includes(type)"
        />
      </template>
    </avue-form>
  </basic-container>
</template>

<script>
import CrudTitle from '@/components/base/title'
import { validateFileList } from '@/util/validate'
const dic = {
  inspectResult: [
    {
      label: '通过',
      value: '0'
    },
    {
      label: '不通过',
      value: '1'
    }
  ]
}
export default {
  name: 'SampleInfo',
  inject: ['type'],
  props: {
    title: {
      type: String,
      default: ''
    },
    loading: {
      type: Boolean,
      default: false
    },
    info: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  components: { CrudTitle },
  data() {
    return {
      form: {},
      option: {
        labelWidth: 120,
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: '检查内容',
            prop: 'inspectContent',
            type: 'textarea',
            maxlength: 500,
            minRows: 4,
            maxRows: 6,
            span: 24,
            disabled: true
          },
          {
            label: '检查标准',
            prop: 'inspectStandard',
            type: 'textarea',
            maxlength: 500,
            minRows: 4,
            maxRows: 6,
            span: 24,
            disabled: true
          },
          {
            label: '单项检查结果',
            prop: 'inspectResult',
            type: 'radio',
            props: {
              label: 'label',
              value: 'value'
            },
            value: '0',
            dicData: dic.inspectResult,
            rules: [
              {
                required: true,
                message: '请选择单项检查结果',
                trigger: 'change'
              }
            ],
            span: 24
          },
          {
            label: '检查结果说明',
            prop: 'inspectResultRemark',
            type: 'textarea',
            maxlength: 500,
            minRows: 4,
            maxRows: 6,
            span: 24,
            rules: [
              {
                required: true,
                message: '请输入检查结果说明',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '附件',
            span: 24,
            formslot: true,
            prop: 'attachVOS',
            type: 'upload',
            rules: [
              {
                required: true,
                message: '请上传附件',
                validator: validateFileList,
                trigger: 'blur'
              }
            ]
          }
        ]
      }
    }
  },
  watch: {
    form: {
      handler(val) {
        this.$emit('update:info', val)
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    validateForm() {
      let flag = null
      this.$refs.form.validate((valid, done) => {
        if (valid) {
          flag = true
        } else {
          flag = false
        }
      })
      return flag
    }
  }
}
</script>

<style></style>
